package com.bysj.lms.controller;


import com.bysj.lms.common.ResultModel;
import com.bysj.lms.pojo.entity.Cabinetinfo;
import com.bysj.lms.service.ICabinetinfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaojiakai
 * @since 2022-02-04
 */
@RestController
@RequestMapping("/cabinetinfo")
@Api(tags = "机柜管理")
public class CabinetinfoController {

    @Autowired
    ICabinetinfoService cabinetinfoService;

    @ApiOperation("查看机柜列表")
    @GetMapping("/list")
    public ResultModel getList(Integer page,Integer count,String status){
        PageInfo list = cabinetinfoService.getList(page, count, status);
        return ResultModel.success("查询成功",list);
    }

    @ApiOperation(value = "批量添加",notes = "初始化机柜信息")
    @PostMapping("/adds")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roomId",value = "机房id"),
            @ApiImplicitParam(name = "ecNumber",value = "机柜编号"),
            @ApiImplicitParam(name = "row",value = "行数,该机柜一共几行"),
            @ApiImplicitParam(name = "col",value = "列数，该机柜一共几列"),
    })
    public ResultModel adds(String roomId,String ecNumber,Integer row,Integer col){
        boolean adds = cabinetinfoService.adds(roomId, ecNumber, row, col);
        return adds?ResultModel.success():ResultModel.failure();
    }

    @ApiOperation("添加单个")
    @PostMapping("/add")
    public ResultModel add(@RequestBody Cabinetinfo cabinetinfo){
        boolean save = cabinetinfoService.save(cabinetinfo);
        return save?ResultModel.success():ResultModel.failure();
    }

    @ApiOperation("修改")
    @PutMapping("/edit")
    public ResultModel edit(@RequestBody Cabinetinfo cabinetinfo){
        boolean update = cabinetinfoService.updateById(cabinetinfo);
        return update?ResultModel.success():ResultModel.failure();
    }
    @ApiOperation("删除")
    @DeleteMapping("/delete")
    public ResultModel delete(Integer id){
        boolean delete = cabinetinfoService.removeById(id);
        return delete?ResultModel.success():ResultModel.failure();
    }
}

